package cn.com.gas.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.com.common.constants.Constants;
import cn.com.common.result.DataResult;
import cn.com.gas.entity.GasHardwareEntity;
import cn.com.gas.service.GasHardwareService;
import cn.com.system.service.impl.HttpSessionService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.List;

/**
 * 加油明细
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2024-03-22 11:21:42
 */
@Controller
@RequestMapping("/gas/hardware")
public class GasHardwareController {
	@Autowired
	private GasHardwareService gasHardwareService;
	@Autowired
	private HttpSessionService httpSessionService;
	
	
	@ApiOperation(value = "新增")
	@PostMapping("/add")
	// @RequiresPermissions("gasHardware:add")
	@ResponseBody
	public DataResult add(@RequestBody GasHardwareEntity gasHardware) {
		
		gasHardware.setCreateTime(new Date());
		gasHardware.setCreateId(httpSessionService.getCurrentUserId());
		gasHardware.setDeleted(Constants.DELETEED_NOT);
		gasHardwareService.save(gasHardware);
		return DataResult.success();
	}

	@ApiOperation(value = "删除")
	@DeleteMapping("/delete")
	// @RequiresPermissions("gasHardware:delete")
	@ResponseBody
	public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
		gasHardwareService.removeByIds(ids);
		return DataResult.success();
	}

	@ApiOperation(value = "更新")
	@PutMapping("/update")
	// @RequiresPermissions("gasHardware:update")
	@ResponseBody
	public DataResult update(@RequestBody GasHardwareEntity gasHardware) {
		gasHardwareService.updateById(gasHardware);
		return DataResult.success();
	}
	
	@ApiOperation(value = "刷新")
	@PutMapping("/refresh")
	// @RequiresPermissions("gasHardware:refresh")
	@ResponseBody
	public DataResult refresh(@RequestBody GasHardwareEntity gasHardware) {
		gasHardwareService.updateById(gasHardware);
		return DataResult.success();
	}
	
	
	@SuppressWarnings("rawtypes")
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list")
	// @RequiresPermissions("gasHardware:list")
	@ResponseBody
	public DataResult findListByPage(@RequestBody GasHardwareEntity gasHardware) {
		Page page = new Page(gasHardware.getPage(), gasHardware.getLimit());
		LambdaQueryWrapper<GasHardwareEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		// queryWrapper.eq(GasHardwareEntity::getId, gasHardware.getId());
		@SuppressWarnings("unchecked")
		IPage<GasHardwareEntity> iPage = gasHardwareService.page(page, queryWrapper);
		return DataResult.success(iPage);
	}

}
